<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
        a {
            color: #fff;
            text-decoration: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="col-md-offset-1 col-md-10">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h5>分类LOGO:</h5>
                </div>
                <div class="panel-body">
                    <form action="{:U('Logo/store')}" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="logo">上传logo:</label>
                            <input type="file" name="logo" class="">
                        </div>
                        <div class="form-group">
                            <label for="id">选择分类:</label>
                            <select name="id" class="form-control">
                                <option value="0" selected>请选择分类:</option>
                                <?php foreach($datas as $data):?>
                                <option value="<?php echo $data['id']?>"><?php echo str_repeat('-', 6*$data['level']) . $data['name']; ?></option>
                                <?php endforeach;?>
                            </select>
                        </div>
                        <button type="submit" class="btn btn-primary btn-sm">提交</button>
                    </form>
                </div>
                <hr>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <tr>
                                <td>ID</td>
                                <td>分类</td>
                                <td>logo</td>
                                <td>操作</td>
                            </tr>
                            <?php foreach($items as $item):?>
                                <tr>
                                    <td class="ids"><?php echo $item['id'];?></td>
                                    <td><?php echo $item['name'];?></td>
                                    <td><img src="./<?php echo $item['logo'];?>" width="100px" height="50px;"></td>

                                    <td>
                                        <button class="btn btn-primary btn-sm"><a href="{:U('Logo/edit',['id'=>$item['id']])}">修改</a></button>
                                        <button type="submit" class="btn btn-sm btn-danger btn3">删除</button>
                                    </td>
                                </tr>
                            <?php endforeach;?>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script>
        var btn3 = document.getElementsByClassName('btn3');
        var ids = document.getElementsByClassName('ids');
        for(var i=0;i< btn3.length;i++) {
            btn3[i].index = i;
            btn3[i].onclick = function() {
                for(var j=0;j<ids.length;j++) {
                    ids[j].index = j;
                    var id = ids[this.index].innerHTML;
                }
                $.ajax({
                    type: "post",
                    url: "{:U('Logo/destroy')}",
                    data: {"id": id},
                    success: function (data) {
                        window.location.reload();
                    }
                });
            }
        }
    </script>
</body>
</html>